package com.njupt.simulation.utils;

public class getFenceEdgePoint {


    public static double[] getFenceEdgePoint(double longitude, double latitude, double radius, double angle) {

        double EARTH_RADIUS = 6371.0;

        // 转换半径为弧度（电子围栏半径）
        double radiusInRadians = radius / EARTH_RADIUS;

        // 计算边缘点的经纬度
        double lat2 = Math.asin(Math.sin(Math.toRadians(latitude)) * Math.cos(radiusInRadians) +
                Math.cos(Math.toRadians(latitude)) * Math.sin(radiusInRadians) * Math.cos(Math.toRadians(angle)));
        double lon2 = Math.toRadians(longitude) + Math.atan2(Math.sin(Math.toRadians(angle)) * Math.sin(radiusInRadians) * Math.cos(Math.toRadians(latitude)),
                Math.cos(radiusInRadians) - Math.sin(Math.toRadians(latitude)) * Math.sin(lat2));

        // 转换经纬度为度数
        lat2 = Math.toDegrees(lat2);
        lon2 = Math.toDegrees(lon2);

        return new double[]{lon2, lat2,0};
    }

}
